<script language="javascript">
function btnLogin_onclick(){
	if(test_empty(document.frmLogin.txtUid.value)){
		alert(mustInput_Uid);document.frmLogin.txtUid.focus();return false;
	}
	if(test_empty(document.frmLogin.txtPwd.value)){
		alert(mustInput_Pwd);document.frmLogin.txtPwd.focus();return false;
	}
	return true;
}
</script>

<? $errMsg =''?>
<?
$l_notmember = $_lang == 'vn' ? 'You Are Not Yet A Member Of Sleep Express' : 'You Are Not Yet A Member Of Sleep Express';
$l_member    = $_lang == 'vn' ? 'You are Member' : 'Member';

$l_Uid       = $_lang == 'vn' ? 'Username' : 'Username';
$l_Pwd       = $_lang == 'vn' ? 'Password' : 'Password';
$l_ForgotPwd = $_lang == 'vn' ? 'Forgot Password' : 'Forgot Password';

$l_btnRegistry = $_lang == 'vn' ? 'Continue' : 'Continue';
$l_btnLogin    = $_lang == 'vn' ? 'Login' : 'Login';
$l_btnLogout   = $_lang == 'vn' ? 'Logout' : 'Logout';

$l_Welcome      = $_lang == 'vn' ? 'Welcome' : 'Welcome';
$l_LoginSuccess = $_lang == 'vn' ? 'Login Successfully.' : 'Login Successfully.';

if ($_REQUEST['frame']=='logout'){
	unset($_SESSION['member']);
	echo "<script>window.location='./?frame=login'</script>";
}
if(!isset($_SESSION['member']) || $_SESSION['member']==''){
	$flagLogin = false;
}else{
	$flagLogin = true;
}

if($_REQUEST['boxUid']!=''){
	$uid = $_REQUEST['boxUid'];
	$pwd = $_REQUEST['boxPwd'];
	
	if(!isset($_SESSION['member']) || $_SESSION['member']==''){
		$result = mysql_query("select * from tbl_member where uid='".$uid."'",$conn);
		$rows = mysql_num_rows($result);
		if($rows<1){
			$errMsg = $_lang == 'vn'?'Username wrong !':'Username wrong !';
		}else{
			$row = mysql_fetch_array($result);
			if($pwd != $row['pwd']){
				$errMsg = $_lang == 'vn'?'Password wrong !':'Password wrong !';
			}else{
				$flagLogin = true;
			}
		}
	}
}

if (isset($_POST['btnLogin'])){
	$uid = isset($_POST['txtUid']) ? trim($_POST['txtUid']) : "";
	$pwd = isset($_POST['txtPwd']) ? trim($_POST['txtPwd']) : "";
	
	if(!isset($_SESSION['member']) || $_SESSION['member']==''){
		$result = mysql_query("select * from tbl_member where uid='".$uid."'",$conn);
		$rows = mysql_num_rows($result);
		if($rows<1){
			$errMsg = $_lang == 'vn'?'<span style="color:#FF0000"> "Username wrong" !</span>':'Username wrong !';
		}else{
			$row = mysql_fetch_array($result);
			if($pwd != $row['pwd']){
				$errMsg = $_lang == 'vn'?'<span style="color:#FF0000">"Password wrong" !</span>':'Password wrong !';
			}else{
				$flagLogin = true;
			}
		}
	}
}

if($flagLogin){
	$_SESSION['member'] = isset($_SESSION['member'])?$_SESSION['member']:$uid;		
	echo "<script>window.location='./?frame=checkout'</script>";
}else{
?>
<link href="../css/css.css" rel="stylesheet" type="text/css" />
<table align="center" border="0" width="98%" cellpadding="0" cellspacing="0">
	<tr><td height="5"></td></tr>
	<tr>
		<td>

<table border="1" width="100%" cellpadding="0" cellspacing="0" bordercolor="#666666" style="border-collapse:collapse" class="border_table">
	<tr >
		<td height="22" bgcolor="#F5F7FB">
			<span style="FONT-WEIGHT: 700; FONT-SIZE: 10pt;color:#333333">&nbsp;&nbsp;<?=$l_notmember?></span>
		</td>
	</tr>
	
	<tr>
		<td align="center">
			<table border="0" width="98%" cellpadding="0" cellspacing="0">
				<tr><td height="10"></td></tr>
				<tr>
					<td>
				<p align="justify">
				<?=$_lang == 'vn' ? 'To place an order without becoming a member click the Continue button below to place your order securely online' : 'To place an order without becoming a member click the Continue button below to place your order securely online'?>
				</p>
					</td>
				</tr>
				<tr><td height="25"></td></tr>
				<tr>
					<td align="center">
						<input class="buttonorange" onmouseover="this.className='buttonblue'" style="WIDTH: 89px; HEIGHT: 22px" onmouseout="this.className='buttonorange'" type="button" value="<?=$l_btnRegistry?>" name="btnRegistry" onclick="window.location='./?frame=registry'">
					</td>
				</tr>
				<tr><td height="25"></td></tr>
			</table>
		</td>
	</tr>
</table>

<br />

<table border="1" width="100%" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse:collapse" class="border_table">
	<tr>
		<td height="22" bgcolor="#F5F7FB">
			<span style="FONT-WEIGHT: 700; FONT-SIZE: 10pt; color:#333333">&nbsp;&nbsp;<?=$l_member?></span>
		</td>
	</tr>
	<tr>
		<td>
			<table border="0" width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td valign="top">
					<form name="frmLogin" method="POST" action="./">
						<input type="hidden" name="frame" value="login">
						<table border="0" width="100%" cellpadding="0" cellspacing="0">
							<tr><td colspan="3" height="10"></td></tr>
							<tr>
								<td align="right" width="40%"><?=$l_Uid?></td>
								<td width="5"></td>
								<td><input type="text" name="txtUid" class="textbox"></td>
							</tr>
							<tr>
								<td align="right"><?=$l_Pwd?></td>
								<td width="5"></td>
								<td><input type="password" name="txtPwd" class="textbox"></td>
							</tr>
							<tr><td colspan="3" height="10"></td></tr>
							<tr>
								<td align="right"><a href="./?frame=forgotpass">
									<span style="color:#000000; text-decoration:none"><?=$l_ForgotPwd?></span></a></td>
								<td width="5"></td>
								<td>
<input class="buttonorange" onmouseover="this.className='buttonblue'" style="WIDTH: 89px; HEIGHT: 22px" onmouseout="this.className='buttonorange'" type="submit" value="<?=$l_btnLogin?>" name="btnLogin" onclick="return btnLogin_onclick()">
								</td>
							</tr>
							
						</table>
					</form>
					</td>
				</tr>
			</table>
	
		</td>
	</tr>
</table>

		</td>
	</tr>
	<tr><td height="5"></td></tr>
</table>
<? }?>

<? if($errMsg!=''){echo '<p align=center class="err">'.$errMsg.'<br></p>';}?>

  